#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int ipt[1024][1024] = { 0 };
int mx[1024][1024] = { 0 };

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    for (int i = 1; i < n + 1; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            cin >> ipt[i][j];
        }
    }

    for (int i = n; i >= 0; i--)
    {
        for (int j = 1; j <= i; j++)
        {
            mx[i][j] = max(mx[i + 1][j], mx[i + 1][j + 1]) + ipt[i][j];
        }
    }
    
    cout << mx[1][1];
    
    return 0;
}
